start_sec=$(date '+%s')
echo -e "yes\nyes\nyes\n" | sudo bash rpi-clone sda  -L lepi_root
stop_sec=$(date '+%s')
clone_sec=$((stop_sec - start_sec))
sleep 2
fix_partuuid(){
  old_diskid=$(sudo fdisk -l /dev/mmcblk0 | sed -n 's/Disk identifier: 0x\([^ ]*\)/\1/p')
  diskid=$(sudo fdisk -l /dev/sda | sed -n 's/Disk identifier: 0x\([^ ]*\)/\1/p')
  printf "fix partuuid from $old_diskid to $diskid.\n"
  sudo mount /dev/mmcblk0p1 /boot/firmware/
  sudo mount /dev/sda1 /mnt
  sudo cp -r /boot/firmware/* /mnt/
#   rm /mnt/cmdline.txt /mnt/config.txt
#   sudo cp /boot/firmware/config.txt /mnt/config.txt
  sudo sed -i "s/${old_diskid}/${diskid}/" /mnt/cmdline.txt
  sudo umount /dev/sda1
}
fix_partuuid

printf "===============================\n\n"
if [ $clone_sec -gt 30 ]
then
  echo "克隆完成"
  printf "花费时间 - %d:%02d\n" \
      "$((clone_sec / 60))" "$((clone_sec % 60))"
else
  echo "请先将micro SD卡连接读卡器并插入主机USB口"
fi

echo "按退出键退出"
